/*
 * @Author: qsy
 * @Date: 2024-07-22 16:09:04
 * @LastEditors: qsy
 * @LastEditTime: 2025-04-09 21:42:20
 * @Description: 连接wifi
 */

// 头文件格式
#ifndef __WIFI_CONNECT_H__
#define __WIFI_CONNECT_H__

// 包含头文件
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"

#include "lwip/err.h"
#include "lwip/sys.h"
#include "my_mqtt.h"

// 网络测试弘
#define EXAMPLE_ESP_WIFI_SSID      "MERCURY_5B00" // wifi 名称
#define EXAMPLE_ESP_WIFI_PASS      "tzyjy12345678" // wifi 密码


#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT      BIT1

// 扫描WiFi网络
#define MAX_AP_COUNT 3


extern EventGroupHandle_t my_wifi_connected_event_group;


typedef struct wifi_ap_simple_info{
    char ssid[32]; // SSID最大长度为32
    int8_t rssi;
    uint8_t channel;
} wifi_ap_simple_info_t;

typedef struct wifi_scan_result{
    wifi_ap_simple_info_t ap_info[MAX_AP_COUNT];
    uint16_t ap_count;
} wifi_scan_result_t;


/**
 * @description: 初始化wifi模块、以及NVS存储
 * @return {*}
 */
void wifi_model_NVS_init(void);

/**
 * @description: wifi连接
 * @param {uint8_t} scan_result_ap_count
 * @param {char} *password
 * @param {char} *ssid
 * @return {*}
 */
bool wifi_connect(uint8_t scan_result_ap_count, char *password, char *ssid);

#endif
